package com.kabuda.blog.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.kabuda.blog.dao.mapper.ArticleBodyMapper;
import com.kabuda.blog.dao.pojo.ArticleBody;
import com.kabuda.blog.service.ArticleBodyService;
import com.kabuda.blog.vo.ArticleBodyVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author kabuda
 * @create 2023-01-18 10:48
 */
@Service
public class ArticleBodyServiceImpl implements ArticleBodyService {
    @Autowired
    private ArticleBodyMapper articleBodyMapper;

    /**
     * 根据文章id查询文章主体
     * @param id
     * @return
     */
    @Override
    public ArticleBodyVo getArticleBodyByArticleId(Long id) {
        LambdaQueryWrapper<ArticleBody> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ArticleBody::getArticleId, id);
        ArticleBody articleBody = articleBodyMapper.selectOne(queryWrapper);
        ArticleBodyVo articleBodyVo = new ArticleBodyVo();
        BeanUtils.copyProperties(articleBody,articleBodyVo);
        return articleBodyVo;
    }
}
